#include "LedControl.h"

#include "WProgram.h"
void setup();
void loop();
void runLED(int x,int data);
void lineOn(int getRow, int getData, int Arr);
int i=0;
int incomingByte = 0;
int incomingCharInt[10] = {0,0,0,0,0,0,0,0,0,0};
//\u55ae\u6392\u7684\u4e8c\u9032\u5236\u6548\u679c\u5c0d\u61c9
                  //0         1         2         3         4         5         6         7         8         9
byte setArr[255] = {B00000100,B00001000,B00010000,B00100000,B01000000,B10000000,B00000000,B11111100,B00001100,B00010000,//1
                    B00010100,B00011000,B00011100,B00100100,B00101000,B00101100,B00110000,B00110100,B00111000,B00111100,//2
                    B01000100,B01001000,B01001100,B01010000,B01010100,B01011000,B01011100,B01100000,B01100100,B01101000,//3
                    B01101100,B01110000,B01110100,B01111000,B01111100,B10000100,B10001000,B10001100,B10010000,B10010100,//4
                    B10011000,B10011100,B10100000,B10100100,B10101000,B10101100,B10110000,B10110100,B10111000,B10111100,//5
                    B11000000,B11000100,B11001000,B11001100,B11010000,B11010100,B11011000,B11011100,B11100000,B11100100,//6
                    B11101000,B11101100,B11110000,B11110100,B11111000 };                                                //7
//====================================================================

int getavg[10]={0,0,0,0,0,0,0,0,0,0};
int getAVGon=0;
int getAVGonRow =0;
//setup output pin
LedControl lc=LedControl(4,5,6,8);
LedControl lc2=LedControl(7,8,9,8);
LedControl lc3=LedControl(10,11,12,8);	
//main================================================================
void setup() {
  Serial.begin(9600);
  int devices=lc.getDeviceCount();
  for(int address=0;address<devices;address++) {
    lc.shutdown(address,false);
    lc.setIntensity(address,15);
    lc.clearDisplay(address);
    
    lc2.shutdown(address,false);
    lc2.setIntensity(address,15);
    lc2.clearDisplay(address);
    
    lc3.shutdown(address,false);
    lc3.setIntensity(address,15);
    lc3.clearDisplay(address);
  }
 	
}

void loop() {
  digitalWrite(13,1);
	
	if (Serial.available() > 0) {		
		incomingByte = Serial.read();	
		//Serial.print("I received: ");
		//Serial.println(incomingByte);
                
           if(i == 9){
             incomingCharInt[9] = incomingByte; 
             
             for(int x=0;x<10;x++){
             if(incomingCharInt[x] >=0 && incomingCharInt[x] <=95){
                runLED(x,incomingCharInt[x]);
              }
               switch(incomingCharInt[x]){
                //==========\u5c0d\u61c9\u6548\u679c\u7684\u865f\u78bc===================== 
                //96-111  \u4e0a\u5230\u4e0b \u55ae\u5217 \u4eae
                case 96: //row1
                     runLED(x,96);
                break;
                case 97: //row2
                     runLED(x,97);
                break;
                case 98: //row3
                     runLED(x,98);
                break;
                case 99: //row4
                     runLED(x,99);
                break;
                case 100: //row5
                     runLED(x,100);
                break;
                case 101: //row6
                     runLED(x,101);
                break;
                case 102: //row7
                     runLED(x,102);
                break;
                case 103: //row8
                     runLED(x,103);
                break;
                case 104: //row9
                     runLED(x,104);
                break;
                case 105: //row10
                     runLED(x,105);
                break;
                case 106: //row11
                     runLED(x,106);
                break;
                case 107: //row12
                     runLED(x,107);
                break;
                case 108: //row13
                     runLED(x,108);
                break;
                case 109: //row14
                     runLED(x,109);
                break;
                case 110: //row15
                     runLED(x,110);
                break;
                case 111: //row16
                     runLED(x,111);
                break;
                case 112: //row1 off
                     runLED(x,112);
                break;
                case 113: //row2 off
                     runLED(x,113);
                break;
                case 114: //row2 off
                     runLED(x,114);
                break;
                case 115: //row2 off
                     runLED(x,115);
                break;
                case 116: //row2 off
                     runLED(x,116);
                break;
                case 117: //row2 off
                     runLED(x,117);
                break;
                case 118: //row2 off
                     runLED(x,118);
                break;
                case 119: //row2 off
                     runLED(x,119);
                break;
                case 120: //row2 off
                     runLED(x,120);
                break;
                case 121: //row2 off
                     runLED(x,121);
                break;
                case 122: //row2 off
                     runLED(x,122);
                break;
                case 123: //row2 off
                     runLED(x,123);
                break;
                case 124: //row2 off
                     runLED(x,124);
                break;
                case 125: //row2 off
                     runLED(x,125);
                break;
                case 126: //row2 off
                     runLED(x,126);
                break;
                case 127: 
                     runLED(x,127);
                break;
                case 128:
runLED(x,128);
break;
case 129:
runLED(x,129);
break;
case 130:
runLED(x,130);
break;
case 131:
runLED(x,131);
break;
case 132:
runLED(x,132);
break;
case 133:
runLED(x,133);
break;
case 134:
runLED(x,134);
break;
case 135:
runLED(x,135);
break;
case 136:
runLED(x,136);
break;
case 137:
runLED(x,137);
break;
case 138:
runLED(x,138);
break;
case 139:
runLED(x,139);
break;
case 140:
runLED(x,140);
break;
case 141:
runLED(x,141);
break;
case 142:
runLED(x,142);
break;
case 143:
runLED(x,143);
break;
case 144:
runLED(x,144);
break;
case 145:
runLED(x,145);
break;
case 146:
runLED(x,146);
break;
case 147:
runLED(x,147);
break;
case 148:
runLED(x,148);
break;
case 149:
runLED(x,149);
break;
case 150:
runLED(x,150);
break;
case 151:
runLED(x,151);
break;
case 152:
runLED(x,152);
break;
case 153:
runLED(x,153);
break;
case 154:
runLED(x,154);
break;
case 155:
runLED(x,155);
break;
case 156:
runLED(x,156);
break;
case 157:
runLED(x,157);
break;
case 158:
runLED(x,158);
break;
case 159:
runLED(x,159);
break;
case 160:
runLED(x,160);
break;
case 161:
runLED(x,161);
break;
case 162:
runLED(x,162);
break;
case 163:
runLED(x,163);
break;
case 164:
runLED(x,164);
break;
case 165:
runLED(x,165);
break;
case 166:
runLED(x,166);
break;
case 167:
runLED(x,167);
break;
case 168:
runLED(x,168);
break;
case 169:
runLED(x,169);
break;
case 170:
runLED(x,170);
break;
case 171:
runLED(x,171);
break;
case 172:
runLED(x,172);
break;
case 173:
runLED(x,173);
break;
case 174:
runLED(x,174);
break;
case 175:
runLED(x,175);
break;
case 176:
runLED(x,176);
break;
case 177:
runLED(x,177);
break;
case 178:
runLED(x,178);
break;
case 179:
runLED(x,179);
break;
case 180:
runLED(x,180);
break;
case 181:
runLED(x,181);
break;
case 182:
runLED(x,182);
break;
case 183:
runLED(x,183);
break;
case 184:
runLED(x,184);
break;
case 185:
runLED(x,185);
break;
case 186:
runLED(x,186);
break;
case 187:
runLED(x,187);
break;


                case 254:                   
                     runLED(x,254);                         
                break;
                case 255:                   
                     runLED(x,255);                         
                break;
                 //==========\u5c0d\u61c9\u6548\u679c\u7684\u865f\u78bc=====================                
             }
             
             }
             i=0;
             for(int bb=0;bb<10;bb++){
                incomingCharInt[bb] = 0;
             }
           }else{
             incomingCharInt[i] = incomingByte;
             i+=1;
           }           
           
	}
}

void runLED(int x,int data){
//=============================================     
 if(x == 0 ){
getavg[x] = (int)data / 6;

   if(data < 48 && data >= 0){     
    lc.setRow( 0,getavg[x] ,  setArr[((int)data-getavg[x]*6)]); 
   }
   if(data >= 48 && data <= 95){
    lc.setRow( 1,getavg[x] - 8,  setArr[((int)data-getavg[x]*6)]);
   }
   if(data == 254){
     for(int p1=0;p1<8;p1++){
        lc.setRow(0,p1,setArr[6]);
        lc.setRow(1,p1,setArr[6]);
     }
   }
   if(data == 255){
     for(int p1=0;p1<8;p1++){
        lc.setRow(0,p1,setArr[7]);
        lc.setRow(1,p1,setArr[7]);
     }
   }
   if(data >=96 && data <= 111){
      lineOn(x,data,7);  //ON
   }
   if(data >=112 && data <= 127){
      lineOn(x,data,6);  //off
   }
   if(data >=140 && data <= 155){
      lineOn(x,data,13);  //001001 00
   }
   if(data >=156 && data <= 171){
      lineOn(x,data,21);  //010010 00
   }
   if(data >=172 && data <= 187){
      lineOn(x,data,48);  //100100 00
   }
   if(data >=134 && data <= 139){
      lineOn(x,data,6); //off line
   }
   switch(data){
    case 128:
    lineOn(x,data,0);
    break;
    case 129:
    lineOn(x,data,1);
    break;
    case 130:
    lineOn(x,data,2);
    break;
    case 131:
    lineOn(x,data,3);
    break;
    case 132:
    lineOn(x,data,4);
    break;
    case 133:
    lineOn(x,data,5);
    break;
    
   }
  
  }
  //..................................................................................
   if(x == 1 ){
  getavg[x] = (int)data / 6;    
   if(data < 48 && data >= 0){      
    lc.setRow( 2,getavg[x] ,  setArr[((int)data-getavg[x]*6)]); 
   }
  if(data >= 48 && data <= 95){
    lc.setRow( 3,getavg[x] - 8,  setArr[((int)data-getavg[x]*6)]);     
   }
   if(data == 254){
     for(int p1=0;p1<8;p1++){
        lc.setRow(2,p1,setArr[6]);
        lc.setRow(3,p1,setArr[6]);
     }
   }
  if(data == 255){
     for(int p1=0;p1<8;p1++){
        lc.setRow(2,p1,setArr[7]);
        lc.setRow(3,p1,setArr[7]);
     }
   }
   if(data >=96 && data <= 111){
      lineOn(x,data,7);  //ON
   }
    if(data >=112 && data <= 127){
      lineOn(x,data,6);  //off
   }
   if(data >=140 && data <= 155){
      lineOn(x,data,13);  //001001 00
   }
   if(data >=156 && data <= 171){
      lineOn(x,data,21);  //010010 00
   }
   if(data >=172 && data <= 187){
      lineOn(x,data,48);  //100100 00
   }
   if(data >=134 && data <= 139){
      lineOn(x,data,6); //off line
   }
   switch(data){
    case 128:
    lineOn(x,data,0);
    break;
    case 129:
    lineOn(x,data,1);
    break;
    case 130:
    lineOn(x,data,2);
    break;
    case 131:
    lineOn(x,data,3);
    break;
    case 132:
    lineOn(x,data,4);
    break;
    case 133:
    lineOn(x,data,5);
    break;
   }

  }
    //..................................................................................
   if(x == 2 ){
  getavg[x] = (int)data / 6;    
  if(data < 48 && data >= 0){    
    lc.setRow( 4,getavg[x] ,  setArr[((int)data-getavg[x]*6)]); 
  }
    if(data >= 48 && data <= 95){
    lc.setRow( 5,getavg[x] - 8,  setArr[((int)data-getavg[x]*6)]);     
   }
 if(data == 254){
     for(int p1=0;p1<8;p1++){
        lc.setRow(4,p1,setArr[6]);
        lc.setRow(5,p1,setArr[6]);
     }
   }
 if(data == 255){
     for(int p1=0;p1<8;p1++){
        lc.setRow(4,p1,setArr[7]);
        lc.setRow(5,p1,setArr[7]);
     }
   }
if(data >=96 && data <= 111){
      lineOn(x,data,7);  //ON
   }
 if(data >=112 && data <= 127){
      lineOn(x,data,6);  //off
   }
   if(data >=140 && data <= 155){
      lineOn(x,data,13);  //001001 00
   }
   if(data >=156 && data <= 171){
      lineOn(x,data,21);  //010010 00
   }
   if(data >=172 && data <= 187){
      lineOn(x,data,48);  //100100 00
   }
   if(data >=134 && data <= 139){
      lineOn(x,data,6); //off line
   }
switch(data){
    case 128:
    lineOn(x,data,0);
    break;
    case 129:
    lineOn(x,data,1);
    break;
    case 130:
    lineOn(x,data,2);
    break;
    case 131:
    lineOn(x,data,3);
    break;
    case 132:
    lineOn(x,data,4);
    break;
    case 133:
    lineOn(x,data,5);
    break;
   }   
  }
  //..................................................................................  
   if(x == 3 ){
  getavg[x] = (int)data / 6;    
  if(data < 48 && data >= 0){    
    lc.setRow( 6,getavg[x] ,  setArr[((int)data-getavg[x]*6)]); 
   } 
   if(data >= 48 && data <= 95){
    lc.setRow( 7,getavg[x] - 8,  setArr[((int)data-getavg[x]*6)]);     
   }
 if(data == 254){
     for(int p1=0;p1<8;p1++){
        lc.setRow(6,p1,setArr[6]);
        lc.setRow(7,p1,setArr[6]);
     }
   }
 if(data == 255){
     for(int p1=0;p1<8;p1++){
        lc.setRow(6,p1,setArr[7]);
        lc.setRow(7,p1,setArr[7]);
     }
   }
if(data >=96 && data <= 111){
      lineOn(x,data,7);  //ON
   }  
   if(data >=112 && data <= 127){
      lineOn(x,data,6);  //off
   }
   if(data >=140 && data <= 155){
      lineOn(x,data,13);  //001001 00
   }
   if(data >=156 && data <= 171){
      lineOn(x,data,21);  //010010 00
   }
   if(data >=172 && data <= 187){
      lineOn(x,data,48);  //100100 00
   }
   if(data >=134 && data <= 139){
      lineOn(x,data,6); //off line
   }
  switch(data){
    case 128:
    lineOn(x,data,0);
    break;
    case 129:
    lineOn(x,data,1);
    break;
    case 130:
    lineOn(x,data,2);
    break;
    case 131:
    lineOn(x,data,3);
    break;
    case 132:
    lineOn(x,data,4);
    break;
    case 133:
    lineOn(x,data,5);
    break;
   } 
  }
  //..................................................................................  
   if(x == 4 ){
  getavg[x] = (int)data / 6;    
  if(data < 48 && data >= 0){  
    lc2.setRow( 0,getavg[x] ,  setArr[((int)data-getavg[x]*6)]); 
   }
    if(data >= 48 && data <= 95){
    lc2.setRow( 1,getavg[x] - 8,  setArr[((int)data-getavg[x]*6)]);     
   }
 if(data == 254){
     for(int p1=0;p1<8;p1++){
        lc2.setRow(0,p1,setArr[6]);
        lc2.setRow(1,p1,setArr[6]);
     }
   }
 if(data == 255){
     for(int p1=0;p1<8;p1++){
        lc2.setRow(0,p1,setArr[7]);
        lc2.setRow(1,p1,setArr[7]);
     }
   }
if(data >=96 && data <= 111){
      lineOn(x,data,7);  //ON
   }
 if(data >=112 && data <= 127){
      lineOn(x,data,6);  //off
   }
   if(data >=140 && data <= 155){
      lineOn(x,data,13);  //001001 00
   }
   if(data >=156 && data <= 171){
      lineOn(x,data,21);  //010010 00
   }
   if(data >=172 && data <= 187){
      lineOn(x,data,48);  //100100 00
   }
   if(data >=134 && data <= 139){
      lineOn(x,data,6); //off line
   }
switch(data){
    case 128:
    lineOn(x,data,0);
    break;
    case 129:
    lineOn(x,data,1);
    break;
    case 130:
    lineOn(x,data,2);
    break;
    case 131:
    lineOn(x,data,3);
    break;
    case 132:
    lineOn(x,data,4);
    break;
    case 133:
    lineOn(x,data,5);
    break;
   }   
  }
  //..................................................................................  
   if(x == 5 ){
  getavg[x] = (int)data / 6;    
 if(data < 48 && data >= 0){     
    lc2.setRow( 2,getavg[x] ,  setArr[((int)data-getavg[x]*6)]); 
   } 
   if(data >= 48 && data <= 95){
    lc2.setRow( 3,getavg[x] - 8,  setArr[((int)data-getavg[x]*6)]);     
   }
if(data == 254){
     for(int p1=0;p1<8;p1++){
        lc2.setRow(2,p1,setArr[6]);
        lc2.setRow(3,p1,setArr[6]);
     }
   }   
   if(data == 255){
     for(int p1=0;p1<8;p1++){
        lc2.setRow(2,p1,setArr[7]);
        lc2.setRow(3,p1,setArr[7]);
     }
   }
   if(data >=96 && data <= 111){
      lineOn(x,data,7);  //ON
   }
    if(data >=112 && data <= 127){
      lineOn(x,data,6);  //off
   }
   if(data >=140 && data <= 155){
      lineOn(x,data,13);  //001001 00
   }
   if(data >=156 && data <= 171){
      lineOn(x,data,21);  //010010 00
   }
   if(data >=172 && data <= 187){
      lineOn(x,data,48);  //100100 00
   }
   if(data >=134 && data <= 139){
      lineOn(x,data,6); //off line
   }
   switch(data){
    case 128:
    lineOn(x,data,0);
    break;
    case 129:
    lineOn(x,data,1);
    break;
    case 130:
    lineOn(x,data,2);
    break;
    case 131:
    lineOn(x,data,3);
    break;
    case 132:
    lineOn(x,data,4);
    break;
    case 133:
    lineOn(x,data,5);
    break;
   }
  }
  //..................................................................................  
   if(x == 6 ){
  getavg[x] = (int)data / 6;   
  if(data < 48 && data >= 0){      
    lc2.setRow( 4,getavg[x] ,  setArr[((int)data-getavg[x]*6)]); 
   }
    if(data >= 48 && data <= 95){
    lc2.setRow( 5,getavg[x] - 8,  setArr[((int)data-getavg[x]*6)]);     
   }
if(data == 254){
     for(int p1=0;p1<8;p1++){
        lc2.setRow(4,p1,setArr[6]);
        lc2.setRow(5,p1,setArr[6]);
     }
   }
if(data == 255){
     for(int p1=0;p1<8;p1++){
        lc2.setRow(4,p1,setArr[7]);
        lc2.setRow(5,p1,setArr[7]);
     }
   }
if(data >=96 && data <= 111){
      lineOn(x,data,7);  //ON
   }
 if(data >=112 && data <= 127){
      lineOn(x,data,6);  //off
   }
   if(data >=140 && data <= 155){
      lineOn(x,data,13);  //001001 00
   }
   if(data >=156 && data <= 171){
      lineOn(x,data,21);  //010010 00
   }
   if(data >=172 && data <= 187){
      lineOn(x,data,48);  //100100 00
   }
   if(data >=134 && data <= 139){
      lineOn(x,data,6); //off line
   }
switch(data){
    case 128:
    lineOn(x,data,0);
    break;
    case 129:
    lineOn(x,data,1);
    break;
    case 130:
    lineOn(x,data,2);
    break;
    case 131:
    lineOn(x,data,3);
    break;
    case 132:
    lineOn(x,data,4);
    break;
    case 133:
    lineOn(x,data,5);
    break;
   }   
  }
  //..................................................................................  
   if(x == 7 ){
  getavg[x] = (int)data / 6;    
  if(data < 48 && data >= 0){    
    lc2.setRow( 6,getavg[x] ,  setArr[((int)data-getavg[x]*6)]); 
   }
      if(data >= 48 && data <= 95){
    lc2.setRow( 7,getavg[x] - 8,  setArr[((int)data-getavg[x]*6)]);     
   }
if(data == 254){
     for(int p1=0;p1<8;p1++){
        lc2.setRow(6,p1,setArr[6]);
        lc2.setRow(7,p1,setArr[6]);
     }
   }
if(data == 255){
     for(int p1=0;p1<8;p1++){
        lc2.setRow(6,p1,setArr[7]);
        lc2.setRow(7,p1,setArr[7]);
     }
   }
if(data >=96 && data <= 111){
      lineOn(x,data,7);  //ON
   }
 if(data >=112 && data <= 127){
      lineOn(x,data,6);  //off
   }
   if(data >=140 && data <= 155){
      lineOn(x,data,13);  //001001 00
   }
   if(data >=156 && data <= 171){
      lineOn(x,data,21);  //010010 00
   }
   if(data >=172 && data <= 187){
      lineOn(x,data,48);  //100100 00
   }
   if(data >=134 && data <= 139){
      lineOn(x,data,6); //off line
   }
switch(data){
    case 128:
    lineOn(x,data,0);
    break;
    case 129:
    lineOn(x,data,1);
    break;
    case 130:
    lineOn(x,data,2);
    break;
    case 131:
    lineOn(x,data,3);
    break;
    case 132:
    lineOn(x,data,4);
    break;
    case 133:
    lineOn(x,data,5);
    break;
   }   
  }
   //.................................................................................. 
   if(x == 8 ){
  getavg[x] = (int)data / 6;    
   if(data < 48 && data >= 0){    
    lc3.setRow( 0,getavg[x] ,  setArr[((int)data-getavg[x]*6)]); 
   }
      if(data >= 48 && data <= 95){
    lc3.setRow( 1,getavg[x] - 8,  setArr[((int)data-getavg[x]*6)]);     
   }
if(data == 254){
     for(int p1=0;p1<8;p1++){
        lc3.setRow(0,p1,setArr[6]);
        lc3.setRow(1,p1,setArr[6]);
     }
   }
if(data == 255){
     for(int p1=0;p1<8;p1++){
        lc3.setRow(0,p1,setArr[7]);
        lc3.setRow(1,p1,setArr[7]);
     }
   }
if(data >=96 && data <= 111){
      lineOn(x,data,7);  //ON
   }
 if(data >=112 && data <= 127){
      lineOn(x,data,6);  //off
   }
   if(data >=140 && data <= 155){
      lineOn(x,data,13);  //001001 00
   }
   if(data >=156 && data <= 171){
      lineOn(x,data,21);  //010010 00
   }
   if(data >=172 && data <= 187){
      lineOn(x,data,48);  //100100 00
   }
   if(data >=134 && data <= 139){
      lineOn(x,data,6); //off line
   }
switch(data){
    case 128:
    lineOn(x,data,0);
    break;
    case 129:
    lineOn(x,data,1);
    break;
    case 130:
    lineOn(x,data,2);
    break;
    case 131:
    lineOn(x,data,3);
    break;
    case 132:
    lineOn(x,data,4);
    break;
    case 133:
    lineOn(x,data,5);
    break;
   }   
  }
   //.................................................................................. 
  if(x == 9 ){
  getavg[x] = (int)data / 6;    
  if(data < 48 && data >= 0){    
    lc3.setRow( 2,getavg[x] ,  setArr[((int)data-getavg[x]*6)]); 
   }
      if(data >= 48 && data <= 95){
    lc3.setRow( 3,getavg[x] - 8,  setArr[((int)data-getavg[x]*6)]);     
   }
if(data == 254){
     for(int p1=0;p1<8;p1++){
        lc3.setRow(2,p1,setArr[6]);
        lc3.setRow(3,p1,setArr[6]);
     }
   }
if(data == 255){
     for(int p1=0;p1<8;p1++){
        lc3.setRow(2,p1,setArr[7]);
        lc3.setRow(3,p1,setArr[7]);
     }
   }
if(data >=96 && data <= 111){
      lineOn(x,data,7);  //ON
   }
 if(data >=112 && data <= 127){
      lineOn(x,data,6);  //off
   }
   if(data >=140 && data <= 155){
      lineOn(x,data,13);  //001001 00
   }
   if(data >=156 && data <= 171){
      lineOn(x,data,21);  //010010 00
   }
   if(data >=172 && data <= 187){
      lineOn(x,data,48);  //100100 00
   }
   if(data >=134 && data <= 139){
      lineOn(x,data,6); //off line
   }
switch(data){
    case 128:
    lineOn(x,data,0);
    break;
    case 129:
    lineOn(x,data,1);
    break;
    case 130:
    lineOn(x,data,2);
    break;
    case 131:
    lineOn(x,data,3);
    break;
    case 132:
    lineOn(x,data,4);
    break;
    case 133:
    lineOn(x,data,5);
    break;
   }   
  }
   //.................................................................................. 
  data = 0;
//============================================= 
//\u6e05\u9664\u524d\u9762\u7684\u5e8f\u5217\u8cc7\u6599
      for(int h=0;h<10;h++){        
          getavg[h] = 0;
      }    
}

void lineOn(int getRow, int getData, int Arr){
 if(getData >=96 && getData <= 111){  
  getAVGon = getData -96;
  getAVGonRow = getAVGon / 8;
 }
  if(getData >=112 && getData <= 127){
    getAVGon = getData -112;
    getAVGonRow = getAVGon / 8;
  }
  if(getData >=140 && getData <= 155){
    getAVGon = getData -140;
    getAVGonRow = getAVGon / 8;
  }
  if(getData >=156 && getData <= 171){
    getAVGon = getData -156;
    getAVGonRow = getAVGon / 8;
  }
  if(getData >=172 && getData <= 187){
    getAVGon = getData -172;
    getAVGonRow = getAVGon / 8;
  }
 
  
    switch(getRow){
    case 0:
      if(getAVGonRow >= 0 && getAVGonRow < 1){
        lc.setRow(0,getAVGon,setArr[Arr]);
      }
      if(getAVGonRow >= 1 && getAVGonRow < 2){
        lc.setRow(1,getAVGon-8,setArr[Arr]);
      }
      if(getData >=128 && getData <= 133){
        for(int xx=0;xx<8;xx++){
          lc.setRow(0,xx,setArr[Arr]);
          lc.setRow(1,xx,setArr[Arr]);
        }        
      }
      if(getData >=134 && getData <= 139){
        for(int xx=0;xx<8;xx++){
          lc.setRow(0,xx,setArr[Arr]);
          lc.setRow(1,xx,setArr[Arr]);
        }
      }
    break;
    case 1:
      if(getAVGonRow >= 0 && getAVGonRow < 1){
        lc.setRow(2,getAVGon,setArr[Arr]);
      }
      if(getAVGonRow >= 1 && getAVGonRow < 2){
        lc.setRow(3,getAVGon-8,setArr[Arr]);
      }
      if(getData >=128 && getData <= 133){
        for(int xx=0;xx<8;xx++){
          lc.setRow(2,xx,setArr[Arr]);
          lc.setRow(3,xx,setArr[Arr]);
        }        
      }
      if(getData >=134 && getData <= 139){
        for(int xx=0;xx<8;xx++){
          lc.setRow(2,xx,setArr[Arr]);
          lc.setRow(3,xx,setArr[Arr]);
        }
      }
    break;
    case 2:
      if(getAVGonRow >= 0 && getAVGonRow < 1){
        lc.setRow(4,getAVGon,setArr[Arr]);
      }
      if(getAVGonRow >= 1 && getAVGonRow < 2){
        lc.setRow(5,getAVGon-8,setArr[Arr]);
      }
      if(getData >=128 && getData <= 133){
        for(int xx=0;xx<8;xx++){
          lc.setRow(4,xx,setArr[Arr]);
          lc.setRow(5,xx,setArr[Arr]);
        }        
      }
      if(getData >=134 && getData <= 139){
        for(int xx=0;xx<8;xx++){
          lc.setRow(4,xx,setArr[Arr]);
          lc.setRow(5,xx,setArr[Arr]);
        }
      }
    break;
    case 3:
      if(getAVGonRow >= 0 && getAVGonRow < 1){
        lc.setRow(6,getAVGon,setArr[Arr]);
      }
      if(getAVGonRow >= 1 && getAVGonRow < 2){
        lc.setRow(7,getAVGon-8,setArr[Arr]);
      }
      if(getData >=128 && getData <= 133){
        for(int xx=0;xx<8;xx++){
          lc.setRow(6,xx,setArr[Arr]);
          lc.setRow(7,xx,setArr[Arr]);
        }        
      }
      if(getData >=134 && getData <= 139){
        for(int xx=0;xx<8;xx++){
          lc.setRow(6,xx,setArr[Arr]);
          lc.setRow(7,xx,setArr[Arr]);
        }
      }
    break;
    case 4:
      if(getAVGonRow >= 0 && getAVGonRow < 1){
        lc2.setRow(0,getAVGon,setArr[Arr]);
      }
      if(getAVGonRow >= 1 && getAVGonRow < 2){
        lc2.setRow(1,getAVGon-8,setArr[Arr]);
      }
      if(getData >=128 && getData <= 133){
        for(int xx=0;xx<8;xx++){
          lc2.setRow(0,xx,setArr[Arr]);
          lc2.setRow(1,xx,setArr[Arr]);
        }        
      }
      if(getData >=134 && getData <= 139){
        for(int xx=0;xx<8;xx++){
          lc2.setRow(0,xx,setArr[Arr]);
          lc2.setRow(1,xx,setArr[Arr]);
        }
      }
    break;
    case 5:
      if(getAVGonRow >= 0 && getAVGonRow < 1){
        lc2.setRow(2,getAVGon,setArr[Arr]);
      }
      if(getAVGonRow >= 1 && getAVGonRow < 2){
        lc2.setRow(3,getAVGon-8,setArr[Arr]);
      }
      if(getData >=128 && getData <= 133){
        for(int xx=0;xx<8;xx++){
          lc2.setRow(2,xx,setArr[Arr]);
          lc2.setRow(3,xx,setArr[Arr]);
        }        
      }
      if(getData >=134 && getData <= 139){
        for(int xx=0;xx<8;xx++){
          lc2.setRow(2,xx,setArr[Arr]);
          lc2.setRow(3,xx,setArr[Arr]);
        }
      }
    break;
    case 6:
      if(getAVGonRow >= 0 && getAVGonRow < 1){
        lc2.setRow(4,getAVGon,setArr[Arr]);
      }
      if(getAVGonRow >= 1 && getAVGonRow < 2){
        lc2.setRow(5,getAVGon-8,setArr[Arr]);
      }
      if(getData >=128 && getData <= 133){
        for(int xx=0;xx<8;xx++){
          lc2.setRow(4,xx,setArr[Arr]);
          lc2.setRow(5,xx,setArr[Arr]);
        }        
      }
      if(getData >=134 && getData <= 139){
        for(int xx=0;xx<8;xx++){
          lc2.setRow(4,xx,setArr[Arr]);
          lc2.setRow(5,xx,setArr[Arr]);
        }
      }
    break;
    case 7:
      if(getAVGonRow >= 0 && getAVGonRow < 1){
        lc2.setRow(6,getAVGon,setArr[Arr]);
      }
      if(getAVGonRow >= 1 && getAVGonRow < 2){
        lc2.setRow(7,getAVGon-8,setArr[Arr]);
      }
      if(getData >=128 && getData <= 133){
        for(int xx=0;xx<8;xx++){
          lc2.setRow(6,xx,setArr[Arr]);
          lc2.setRow(7,xx,setArr[Arr]);
        }        
      }
      if(getData >=134 && getData <= 139){
        for(int xx=0;xx<8;xx++){
          lc2.setRow(6,xx,setArr[Arr]);
          lc2.setRow(7,xx,setArr[Arr]);
        }
      }
    break;
    case 8:
      if(getAVGonRow >= 0 && getAVGonRow < 1){
        lc3.setRow(0,getAVGon,setArr[Arr]);
      }
      if(getAVGonRow >= 1 && getAVGonRow < 2){
        lc3.setRow(1,getAVGon-8,setArr[Arr]);
      }
      if(getData >=128 && getData <= 133){
        for(int xx=0;xx<8;xx++){
          lc3.setRow(0,xx,setArr[Arr]);
          lc3.setRow(1,xx,setArr[Arr]);
        }        
      }
      if(getData >=134 && getData <= 139){
        for(int xx=0;xx<8;xx++){
          lc3.setRow(0,xx,setArr[Arr]);
          lc3.setRow(1,xx,setArr[Arr]);
        }
      }
    break;
    case 9:
      if(getAVGonRow >= 0 && getAVGonRow < 1){
        lc3.setRow(2,getAVGon,setArr[Arr]);
      }
      if(getAVGonRow >= 1 && getAVGonRow < 2){
        lc3.setRow(3,getAVGon-8,setArr[Arr]);
      }
      if(getData >=128 && getData <= 133){
        for(int xx=0;xx<8;xx++){
          lc3.setRow(2,xx,setArr[Arr]);
          lc3.setRow(3,xx,setArr[Arr]);
        }        
      }
      if(getData >=134 && getData <= 139){
        for(int xx=0;xx<8;xx++){
          lc3.setRow(2,xx,setArr[Arr]);
          lc3.setRow(3,xx,setArr[Arr]);
        }
      }
    break; 
    }
    getAVGon = 0;
    getAVGonRow = 0;
}

int main(void)
{
	init();

	setup();
    
	for (;;)
		loop();
        
	return 0;
}

